// $Id: AnswerController.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*
 *  Copyright (C) 2007 NourY Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Definition of \c Salamanca.DataActivities.UI.Web.WebControls.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

#if (!NET_CF)
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace Salamanca.DataActivities.UI.Web.WebControls
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Non visual control that helps define the default behavior for activity related controls.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    [ProvideProperty("CancelButton", typeof(IButtonControl))]
    [ProvideProperty("EndButton", typeof(IButtonControl))]
    [ProvideProperty("NextButton", typeof(IButtonControl))]
    [ProvideProperty("PreviousButton", typeof(IButtonControl))]
    [NonVisualControl]
    [Designer(typeof(ControlDesigner))]
    public class AnswerController:
        Control,
        IExtenderProvider
    {
        private class Properties
        {
            public IButtonControl CancelButton;
            public IButtonControl EndButton;
            public IButtonControl NextButton;
            public IButtonControl PreviousButton;
        }

        /// <summary>Initializes a new <see cref="AnswerController" /> instance.</summary>
        public AnswerController()
        {
        }

        /// <summary>Initializes a new <see cref="AnswerController" /> instance.</summary>
        public AnswerController(IContainer container)
        {
            container.Add(this);
        }

        /// <summary>Specifies whether this object can provide its extender properties to the specified object.</summary>
        public bool CanExtend(object extendee)
        {
            return (extendee is IButtonControl);
        }

        /// <summary>Gets the <see cref="IButtonControl" /> that triggers the cancellation of the current activity.</summary>
        [DefaultValue(null)]
        [SRCategory("Category_Activity")]
        public IButtonControl GetCancelButton(Control c)
        {
            return GetProperties(c).CancelButton;
        }

        /// <summary>Defines the <see cref="IButtonControl" /> that will trigger the cancellation of the current activity.</summary>
        public void SetCancelButton(Control c, IButtonControl value)
        {
            GetProperties(c).CancelButton=value;
        }

        /// <summary>Gets the <see cref="IButtonControl" /> that triggers the termination of the current activity.</summary>
        [DefaultValue(null)]
        [SRCategory("Category_Activity")]
        public IButtonControl GetEndButton(Control c)
        {
            return GetProperties(c).EndButton;
        }

        /// <summary>Defines the <see cref="IButtonControl" /> that will trigger the termination of the current activity.</summary>
        public void SetEndButton(Control c, IButtonControl value)
        {
            GetProperties(c).EndButton=value;
        }

        /// <summary>Gets the <see cref="IButtonControl" /> that triggers the continuation of the current activity.</summary>
        [DefaultValue(null)]
        [SRCategory("Category_Activity")]
        public IButtonControl GetNextButton(Control c)
        {
            return GetProperties(c).NextButton;
        }

        /// <summary>Defines the <see cref="IButtonControl" /> that will trigger the continuation of the current activity.</summary>
        public void SetNextButton(Control c, IButtonControl value)
        {
            GetProperties(c).NextButton=value;
        }

        /// <summary>Gets the <see cref="IButtonControl" /> that is triggers the stepping back of the current activity.</summary>
        [DefaultValue(null)]
        [SRCategory("Category_Activity")]
        public IButtonControl GetPreviousButton(Control c)
        {
            return GetProperties(c).PreviousButton;
        }

        /// <summary>Defines the <see cref="IButtonControl" /> that will trigger the stepping back of the current activity.</summary>
        public void SetPreviousButton(Control c, IButtonControl value)
        {
            GetProperties(c).PreviousButton=value;
        }

        private Properties GetProperties(Control c)
        {
            Properties ret=null;

            if (!_Properties.TryGetValue(c.ID, out ret))
            {
                ret=new Properties();
                _Properties.Add(c.ID, ret);
                //c.Disposed+=new EventHandler(
                //    delegate(object sender, EventArgs e) {
                //        _Properties.Remove(c.ID);
                //    }
                //);
            }

            return ret;
        }

        private static Dictionary<string, Properties> _Properties=new Dictionary<string, Properties>();

    }
}
#endif
